/*
 * main.cc
 *
 *  Created on: Nov 29, 2010
 *      Author: fify
 */

#include <string>
#include <string.h>
#include <stdio.h>

using namespace std;

const int MAX = 50005;
char format[MAX];
char buf[MAX];

int sub_count;
int sub_str[1005];

string result;

int read_and_print(int a)
{
	if(gets(buf) == NULL)
		return -1;

	if(strlen(buf) == 0)
		return -1;

	for(int i = 0;buf[i];i++)
	{
		if(buf[i] < '0' || buf[i] > '9')
			return -1;
	}

	char *p = buf;
	for(p = buf;*p && *p == '0';p++)
		;

	if(strlen(p) == 0)
		result += "0";
	else
		result += p;

	return 0;
}

int read_and_print(const char *a)
{
	if(gets(buf) == NULL)
		return -1;

	result += buf;

	return 0;
}

int print()
{
	result = "";

	for(int i = 0;format[i];)
	{
		if(format[i] != '%')
		{
			result += format[i];
			i++;
			continue;
		}

		if(format[i] == '%')
		{
			switch(format[i+1])
			{
			case 'd':
				if(read_and_print((int)0) < 0)
					return -1;;
				break;
			case 's':
				if(read_and_print("") < 0)
					return -1;
				break;
			case '%':
				result += '%';
				break;
			default:
				return -1;
			}

			i+=2;
		}
	}

	if(gets(buf) != NULL)
	{
		return -1;
	}

	return 0;
}

int main()
{
	freopen("data.in", "r", stdin);
	gets(format);

	if(print() >= 0)
		printf("%s", result.c_str());
	else
		printf("ERROR");

	return 0;
}
